package clustering;

import java.util.HashSet;
import java.util.Set;

import thesis.DataObject;


import com.aliasi.cluster.KMeansClusterer;
import com.aliasi.util.FeatureExtractor;

public class PinakiClusteringAlgorithm {
	private static final int NUMBEROFITERATIONS = 10;
	
	private Set<DataObject> clusterItems;
	private int numberOfClusters;
	
	public PinakiClusteringAlgorithm(int numberOfClusters, Set<DataObject> clusterItems) {
		this.numberOfClusters = numberOfClusters;
		this.clusterItems = clusterItems;
	}
	
	public Set<PinakiCluster> cluster(){
		FeatureExtractor<DataObject> fExtractor = new PinakiFeatureExtractor<DataObject>();
		KMeansClusterer<DataObject> clustering = new KMeansClusterer<DataObject>(fExtractor, numberOfClusters, NUMBEROFITERATIONS, true, 0);
		
		Set<PinakiCluster> result = new HashSet<PinakiCluster>();
		
		Set<Set<DataObject>> clusters = clustering.cluster(clusterItems);
		
		int clusterCount = 0;
		for (Set<DataObject> clusterItems : clusters){
			String clusterId = "pinakiclus" + clusterCount;
			PinakiCluster cluster = new PinakiCluster(clusterId, clusterItems);
			result.add(cluster);
			
			clusterCount++;
		}
		
		return result;
	}
}
